package br.org.sosim.process;

import javax.swing.*;
import f_Console.*;
import u_Consts.*;
import f_PCB.*;
import u_Processo.*;
import u_Kernel.*;
import u_language.*;
import f_Processo.*;

public class TfrmAlteraProcessos extends Form
{
	public int ProcessoSelecionado = 0;
	public TfrmAlteraProcessos()
	{
		InitializeComponent();
	}

	public final void stg1DrawCell(Object Sender, int ACol, int ARow, Rectangle Rect, TGridDrawState State)
	{
		if ((ARow > 0))
		{
			TProcesso _wvar1 = ((TProcesso)(f_Console.Units.f_Console.Kernel.ListaProcessos[ARow - 1]));
			if (ACol == 0)
			{
				//@ Unsupported property or method(C): 'Canvas'
				//@ Unsupported property or method(D): 'brush'
				//@ Unsupported property or method(D): 'Color'
				stg1.Canvas.brush.Color = _wvar1.Cor;
				if (_wvar1.Killed)
				{
					//@ Unsupported property or method(C): 'Canvas'
					//@ Unsupported property or method(D): 'brush'
					//@ Unsupported property or method(D): 'Color'
					stg1.Canvas.brush.Color = System.Drawing.Color.Black;
					//@ Unsupported property or method(C): 'Canvas'
					//@ Unsupported property or method(B): 'FillRect'
					stg1.Canvas.FillRect(Rect);
				}
				else
				{
					//@ Unsupported property or method(C): 'Canvas'
					//@ Unsupported property or method(B): 'Ellipse'
					stg1.Canvas.Ellipse(Rect.Left + 2, Rect.Top + 2, Rect.Right - 2, Rect.Bottom - 2);
				}
			}
			//@ Unsupported property or method(C): 'Canvas'
			//@ Unsupported property or method(D): 'brush'
			//@ Unsupported property or method(D): 'Color'
			stg1.Canvas.brush.Color = System.Drawing.Color.White;
			//@ Unsupported property or method(C): 'Canvas'
			//@ Unsupported property or method(D): 'Font'
			//@ Unsupported property or method(D): 'Color'
			stg1.Canvas.Font.Color = System.Drawing.Color.Black;
			switch (ACol)
			{
				case 1:
					//@ Unsupported property or method(C): 'Canvas'
					//@ Unsupported property or method(B): 'TextRect'
					stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, (_wvar1.PID).toString());
					break;
				case 2:
					if (f_Console.Units.f_Console.B_PrioDin)
					{
						//@ Unsupported property or method(C): 'Canvas'
						//@ Unsupported property or method(B): 'TextRect'
						stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, (_wvar1.PrioBase).toString() + '/' + (_wvar1.Prioridade).toString());
					}
					else
					{
						//@ Unsupported property or method(C): 'Canvas'
						//@ Unsupported property or method(B): 'TextRect'
						stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, (_wvar1.PrioBase).toString());
					}
					break;
				case 3:
					switch (_wvar1.Estado)
					{
						case u_Processo.TEstadoProcesso.Pronto:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0510);
							break;
						case u_Processo.TEstadoProcesso.ProntoOut:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0511);
							break;
						case u_Processo.TEstadoProcesso.Exec:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0512);
							break;
						case u_Processo.TEstadoProcesso.IO:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0513);
							break;
						case u_Processo.TEstadoProcesso.IOOut:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0514);
							break;
						case u_Processo.TEstadoProcesso.Susp:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0515);
							break;
						case u_Processo.TEstadoProcesso.SuspOut:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0516);
							break;
						case u_Processo.TEstadoProcesso.PF:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0517);
							break;
						case u_Processo.TEstadoProcesso.PFOut:
							//@ Unsupported property or method(C): 'Canvas'
							//@ Unsupported property or method(B): 'TextRect'
							stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, u_Consts.Units.u_Consts.msg0518);
							break;
					}
					break;
				case 4:
					//@ Unsupported property or method(C): 'Canvas'
					//@ Unsupported property or method(B): 'TextRect'
					stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, (_wvar1.Tempo_CPU).toString());
					break;
				case 5:
					//@ Unsupported property or method(C): 'Canvas'
					//@ Unsupported property or method(B): 'TextRect'
					stg1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, (_wvar1.WorkingSetSize).toString());
					break;
			}
		}
	}

	public final void Button1Click(Object Sender, System.EventArgs _e1)
	{
		int aux;
		int NovaPrio;
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		aux = stg1.Selection.Top;
		if (aux < 1)
		{
			return;
		}
		TProcesso _wvar1 = ((TProcesso)(f_Console.Units.f_Console.Kernel.ListaProcessos[aux - 1]));
		//@ Unsupported function or procedure: 'InputBox'
		NovaPrio = (int)(InputBox(u_Consts.Units.u_Consts.msg0519 + ' ' + (_wvar1.PID).toString(), u_Consts.Units.u_Consts.msg0520, (_wvar1.PrioBase).toString()));
		if (((NovaPrio < u_Consts.Units.u_Consts.MIN_PRIO) || (NovaPrio > u_Consts.Units.u_Consts.MAX_PRIO)))
		{
			JOptionPane.showConfirmDialog(null, "Erro", null, JOptionPane.DEFAULT_OPTION);
			// MessageBox (Handle, msg0521, nil, MB_OK); Erro
			new RuntimeException("Abort");
		}
		f_Console.Units.f_Console.Kernel.AlteraPrioBase(f_Console.Units.f_Console.Kernel.ListaProcessos[aux - 1], NovaPrio);
		//@ Unsupported property or method(C): 'Repaint'
		stg1.Repaint;
	}

	public final void Button2Click(Object Sender, System.EventArgs _e1)
	{
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		if ((stg1.Selection.Top == 0))
		{
			return;
		}
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		((TProcesso)(f_Console.Units.f_Console.Kernel.ListaProcessos[stg1.Selection.Top - 1])).Kill();
	}

	public final void Button3Click(Object Sender, System.EventArgs _e1)
	{
		int aux;
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		aux = stg1.Selection.Top;
		if (aux < 1)
		{
			return;
		}
		((TProcesso)(f_Console.Units.f_Console.Kernel.ListaProcessos[aux - 1])).setSuspenso(true);
	}

	public final void Button4Click(Object Sender, System.EventArgs _e1)
	{
		int aux;
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		aux = stg1.Selection.Top;
		if (aux < 1)
		{
			return;
		}
		((TProcesso)(f_Console.Units.f_Console.Kernel.ListaProcessos[aux - 1])).setSuspenso(false);
	}

	public final void Button5Click(Object Sender, System.EventArgs _e1)
	{
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		if ((stg1.Selection.Top == 0))
		{
			return;
		}
		//@ Unsupported property or method(C): 'Selection'
		//@ Unsupported property or method(D): 'Top'
		ProcessoSelecionado = stg1.Selection.Top - 1;
		f_PCB.Units.f_PCB.PCB.Show();
	}

	public final void Timer1Timer(Object Sender, System.EventArgs _e1)
	{
		//@ Unsupported property or method(C): 'RowCount'
		stg1.RowCount = f_Console.Units.f_Console.Kernel.ListaProcessos.size() + 1;
		if (this.Visible)
		{
			stg1.Refresh();
		}
	}

	public final void FormCreate(Object Sender, System.EventArgs _e1)
	{
		//@ Unsupported property or method(C): 'RowCount'
		stg1.RowCount = f_Console.Units.f_Console.Kernel.ListaProcessos.size() + 1;
		//@ Unsupported property or method(A): 'Cells'
		stg1.Cells[0][0] = u_Consts.Units.u_Consts.msg0500;
		//@ Unsupported property or method(A): 'Cells'
		stg1.Cells[1][0] = u_Consts.Units.u_Consts.msg0501;
		//@ Unsupported property or method(A): 'Cells'
		stg1.Cells[2][0] = u_Consts.Units.u_Consts.msg0502;
		//@ Unsupported property or method(A): 'Cells'
		stg1.Cells[3][0] = u_Consts.Units.u_Consts.msg0503;
		//@ Unsupported property or method(A): 'Cells'
		stg1.Cells[4][0] = u_Consts.Units.u_Consts.msg0504;
		//@ Unsupported property or method(A): 'Cells'
		stg1.Cells[5][0] = u_Consts.Units.u_Consts.msg0505;
		this.Text = u_Consts.Units.u_Consts.msg9003;
		u_language.Units.u_language.GetLanguageObject().LoadLanguageCaptions("SP", this);
	}

	public final void Button6Click(Object Sender, System.EventArgs _e1)
	{
		f_Processo.Units.f_Processo.Form2.Show();
	}

	// Note: the original parameters are Object Sender, ref TCloseAction Action
	public final void FormClose(Object Sender, System.EventArgs _e1)
	{
		f_Console.Units.f_Console.Form1.Gernciadeprocessos1.Checked = false;
	}

	public final void stg1SelectCell(Object Sender, int ACol, int ARow, tangible.RefObject<Boolean> CanSelect)
	{
		//@ Unsupported property or method(C): 'Canvas'
		//@ Unsupported property or method(D): 'brush'
		//@ Unsupported property or method(D): 'Color'
		stg1.Canvas.brush.Color = System.Drawing.Color.Sliver;
	}

}